import Vue from 'vue'
import FastClick from 'fastclick'
import App from './App'
import router from './router'

import { WechatPlugin, AjaxPlugin, LoadingPlugin, AlertPlugin } from 'vux'

Vue.use(WechatPlugin)
Vue.use(AjaxPlugin)
Vue.use(LoadingPlugin)
Vue.use(AlertPlugin)

FastClick.attach(document.body)
Vue.config.productionTip = false

let onWindowResize = () => {
	let wh = window.innerHeight,
	 	ww = window.innerWidth,
	 	maxWidth = Math.floor(wh * 750 / 1104);

	ww > maxWidth ?
		document.body.style.width = Math.floor(wh * 0.621) + 'px'
	:
		document.body.style.width = ww + 'px';

	document.body.style.height = wh + 'px';
}

onWindowResize();
window.addEventListener('resize', onWindowResize, false);

Vue.prototype.$http = Vue.http.create({
	baseURL: 'http://gywl.prh5.com/api'
});

Vue.prototype.$http.interceptors.request.use((config) => {
    Vue.$vux.loading.show({
    	text: 'Loading'
    });
	return config;
});

Vue.prototype.$http.interceptors.response.use((response) => {
	Vue.$vux.loading.hide();
	return response;
});

Vue.http.post(location.href).then(({data}) => {
	Vue.wechat.config(data);
	let title = '公益未来·SAP青年责任梦想+大赛打响!',
		link = location.href,
		imgUrl = 'http://gywl.prh5.com/static/img/logo.jpg',
		desc = '2018公益未来·SAP青年责任梦想+大赛打响！谁能C位出道，就等你的pick啦!';
	Vue.wechat.ready(() => {
		Vue.wechat.onMenuShareTimeline({
			title,
		    link, 
		    imgUrl
		});
		Vue.wechat.onMenuShareAppMessage({
			title,
		    link, 
		    imgUrl,
		    desc
		});
	})
});



/* eslint-disable no-new */
new Vue({
  router,
  render: h => h(App)
}).$mount('#app-box')
